package com.example.demo.pattern.strategy;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @program: demo
 * @description:
 * @author: yby
 * @create: 2020-06-12 17:25
 **/
@Service
public class StrategyContext {

    @Autowired
    private final Map<String, StrategyFactory> strategyMap = new ConcurrentHashMap<>();

    public StrategyContext(Map<String, StrategyFactory> strategyMap) {
        this.strategyMap.clear();
        strategyMap.forEach((k, v)-> this.strategyMap.put(k, v));
        System.out.println("strategyMap="+strategyMap);
    }

    public String getResource(String poolId){
        System.out.println("strategyMap="+strategyMap.toString());
        return strategyMap.get(poolId).getVpcList(poolId);
    }
}
